<template>
    <view>
        <view class="searchbox">
            <view class="nav-card">
                <block v-for="(item, index) in lecturerList" :key="index">
                    <view :class="'index ' + (currentId == item.id ? 'active' : 'default')" @tap="selShopTc" :id="item.id">
                        <text>{{ item.name }}</text>
                    </view>
                </block>
            </view>
        </view>

        <!-- 搜索组件 -->
		
			<view class="search-wrapper">
			    <view class="searchimg">
			        <image class="img" src="https://xxzhang.oss-cn-hangzhou.aliyuncs.com/%E6%90%9C%E7%B4%A2.png"></image>
			    </view>
			    <view class="search-input">
			        <input placeholder="搜索 讲师 关键字" @input="inputChange" />
			    </view>
			    <view class="search-button" @tap="clickbutton">
			        <image class="img" src="https://xxzhang.oss-cn-hangzhou.aliyuncs.com/%E6%90%9C%E7%B4%A2%E6%8C%89%E9%92%AE.png"></image>
			    </view>
			</view>
	
      

        <view class="appointment">
            <block v-for="(lecturer, index) in lecturer" :key="index">
                <navigator url="url" class="mod-item" :id="lecturer.userId" @tap="details">
                    <view class="mod-signup">
                        <image class="jpimg" src="https://xxzhang.oss-cn-hangzhou.aliyuncs.com/%E9%87%91%E7%89%8C%20%281%29.png"></image>
                    </view>
                    <view class="mod-img">
                        <image :src="lecturer.headImgUrl" mode="widthFix" class="mod-image"></image>
                    </view>
                    <view class="mod-title">
                        <text>{{ lecturer.name }}</text>
                    </view>
                </navigator>
            </block>
        </view>
    </view>
</template>

<script>
// pages/list/list.js
const app = getApp();
var urlPrefix = app.globalData.urlPrefix;
export default {
    data() {
        return {
			token:null,
            name: '',
            currentId: 1,
            lecturer: [],
            lecturerList: [
                {
                    id: 1,
                    name: '全部'
                },
                {
                    id: 2,
                    name: '我的关注'
                }
            ]
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
		var token = uni.getStorageSync('token')
		this.token = token;
		uni.showLoading({
		      title: '加载中',
		});
        let that = this;
        uni.request({
            url: urlPrefix + '/api/applet/userToLecturer/lecturerList?type=1',
            data: {},
            method: 'GET',
            header: {
                'content-type': 'application/json',
                'token': this.token
            },
            success: function (suss) {
                let dataList = suss.data;
                that.setData({
                    lecturer: dataList.datas
                });
				uni.hideLoading();
            }
        });
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
		var userId = uni.getStorageSync('userId');
		
		setTimeout(()=>{
		               let that = this;
		              uni.request({
		                  url: urlPrefix + '/api/applet/userToLecturer/lecturerList?type='+this.currentId+ '&name=' + this.name+'&userId=' + userId,
		                  data: {},
		                  method: 'GET',
		                  header: {
		                      'content-type': 'application/json',
		                      'token': this.token
		                  },
		                  success: function (suss) {
		                      let dataList = suss.data;
		                      that.setData({
		                          lecturer: dataList.datas
		                      });
		                  }
		              });
		               uni.stopPullDownRefresh();  //停止刷新
		               uni.showToast({
		                   title: '刷新成功',
									icon: 'none',
		                   duration: 2000
		               });
		           },1000)
	},
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    onShareTimeline(res) {
        // 分享到朋友圈
        return {};
    },
    methods: {
        inputChange(e) {
            let that = this;
            that.setData({
                name: e.detail.value
            });
        },

        clickbutton: function (e) {
			var userId = uni.getStorageSync('userId');
            let that = this;
            uni.request({
                url: urlPrefix + '/api/applet/userToLecturer/lecturerList?type=' + this.currentId + '&name=' + this.name+'&userId=' + userId,
                method: 'GET',
                header: {
                    'content-type': 'application/json',
                    'token': this.token
                },
                success: function (suss) {
                    let dataList = suss.data;
                    that.setData({
                        lecturer: dataList.datas
                    });
                }
            });
        },

        details: function (res) {
            var id = res.currentTarget.id;
            uni.navigateTo({
                url: '/pages/courseware/courseware?id=' + id
            });
        },

        selShopTc: function (res) {
            var userId = uni.getStorageSync('userId');
            let that = this;
            uni.request({
                url: urlPrefix + '/api/applet/userToLecturer/lecturerList?type=' + res.currentTarget.id + '&name=' + this.name + '&userId=' + userId,
                data: {},
                method: 'GET',
                header: {
                    'content-type': 'application/json',
                    'token': this.token
                },
                success: function (suss) {
                    let dataList = suss.data;
                    that.setData({
                        currentId: res.currentTarget.id,
                        lecturer: dataList.datas
                    });
                }
            });
        }
    }
};
</script>
<style lang="scss">
@import './list.scss';
</style>
